// =============================================================
// CSpace test
// ---------------------------------------
// Author : Woo-Hyun Kim
// Email : woorung@icu.ac.kr or woorung@nhncorp.com
// Date : Sep. 4, 2007
// =============================================================
#include <iostream>

#include "CSpace.h"
#include "CMessage.h"

int main(int argc, char **argv)
{
	CSpace space("purge test");
	CMessage msg1, msg2, msg3;

	msg1.set("purged after 5 sec.");
	msg2.set("purged after 3 sec.");
	msg3.set("not purged");

	cout << "put message : " << msg1.get() << endl;
	cout << "current size = " << space.write(&msg1, 5) << endl;
	cout << "put message : " << msg2.get() << endl;
	cout << "current size = " << space.write(&msg2, 3) << endl;
	cout << "put message : " << msg3.get() << endl;
	cout << "current size = " << space.write(&msg3) << endl;
	cout << "put message : " << msg1.get() << endl;
	cout << "current size = " << space.write(&msg1, 5) << endl;
	cout << "put message : " << msg2.get() << endl;
	cout << "current size = " << space.write(&msg2, 3) << endl;
	cout << "put message : " << msg1.get() << endl;
	cout << "current size = " << space.write(&msg1, 5) << endl;
	cout << "put message : " << msg2.get() << endl;
	cout << "current size = " << space.write(&msg2, 3) << endl;


	while(1) {
		space.purge();
		
		vector< CSmartTemplate<CObject> > all;
		all = space.read(NULL, space.size(), all);
		cout << "-------------- all objects ---------------" << endl;
		for(int i=0;i<all.size();i++) dynamic_cast<CMessage &>(*(all[i])).print();

		sleep(2);
	}

	return 1;
}
